<?php
/**
 * Created by PhpStorm.
 * User: Acer
 * Date: 2022/2/2
 * Time: 16:35
 */
namespace app\admin\controller;

use app\admin\service\LoginService;
use app\admin\service\UserServide;
use app\core\MyController as MyController;
use app\admin\service\ConfigService as ConfigService;
use app\admin\service\AdminService as AdminService;

class Login extends MyController{

    protected  $noNeedAction = ['login','register']; // 不需要校验控制器，通道
    // 操作前置
    protected $beforeActionList = ['my_initialize'];

    // 操作前置方法
    public function my_initialize(){
//        $this->is_admin();  // 权限检查
    }

    // 登录
    public function  login(){
        $data = input();
        if(!isset($data['mobile']) || empty($data['password'])) json_err( -201);
        $res = (new LoginService())->s_login($data);
        // 生成token
        $token= $this->create_token($res['uid'],$this->expire);
        $token_invalid= time()+ ($this->expire - 10);
        if($res) _action_result(200,[
            'role'  =>  $res['role'],
            'token' =>  $token,
            'token_invalid'   =>$token_invalid,
            'name'  =>  $res['name']
        ],'操作成功！');
        json_err( -205);
    }
}